﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeGame
{
    class Controller
    {

        private Snake _snake;
        private Game _game;


        public Controller(Snake s, Game g)
        {
            _snake = s;
            _game = g;

        }


        public void SnakeControl()
        {
            if (Console.KeyAvailable)
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.UpArrow:
                        if (_snake.Head.X != _snake.Body[0].X) { _snake.Direction = Direction.Up; }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (_snake.Head.Y != _snake.Body[0].Y) { _snake.Direction = Direction.Left; }
                        break;

                    case ConsoleKey.RightArrow:
                        if (_snake.Head.Y != _snake.Body[0].Y) { _snake.Direction = Direction.Right; }
                        break;

                    case ConsoleKey.DownArrow:
                        if (_snake.Head.X != _snake.Body[0].X) { _snake.Direction = Direction.Down; }
                        break;

                    case ConsoleKey.Spacebar:
                        Console.SetCursorPosition(17, 13);
                        Console.WriteLine("-- P A U S E --");
                        Console.ReadKey();
                        Console.Clear();
                        break;

                    case ConsoleKey.Escape:
                        this._game.Go = false;
                        break;
                }
            }
        }

        public void GameControl(ConsoleKeyInfo key)
        {
            switch (key.Key)
            {
                case ConsoleKey.Escape:
                case ConsoleKey.N:
                    _game.Go = false;
                    break;

                case ConsoleKey.Y:
                case ConsoleKey.Enter:
                    _game.Go = true;
                    break;
            }
        }
    }

}
